/*
 * 描          述:  <描述>
 * 修  改   人:  Administrator
 * 修改时间:  2019年6月23日
 * <修改描述:>
 */
package com.tx.component.servicelogger.starter;

import com.tx.component.servicelogger.support.ServiceLoggerMapperRegister;
import com.tx.component.servicelogger.support.ServiceLoggerRegistry;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Import;

/**
 * 权限容器自动配置项<br/>
 * <功能详细描述>
 *
 * @author Administrator
 * @version [版本号, 2019年6月23日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@EnableAspectJAutoProxy
@Configuration
@Import({ServiceLoggerMapperRegister.class})
public class ServiceLoggerPersisterConfiguration {
    
    /*@Bean(name = "createDateLogArgHandler")
    public CreateDateLogArgHandler createDateLogArgHandler() {
        CreateDateLogArgHandler handler = new CreateDateLogArgHandler();
        return handler;
    }
    
    @Bean(name = "sessionAttributesLogArgHandler")
    public SessionAttributesLogArgHandler sessionAttributesLogArgHandler() {
        SessionAttributesLogArgHandler handler = new SessionAttributesLogArgHandler();
        return handler;
    }*/

    /*@Bean(name = "serviceLoggerAop")
    public ServiceLoggerAop serviceLoggerAop(
            List<LogArgumentHandler> handlers) {
        ServiceLoggerAop aop = new ServiceLoggerAop(handlers);
        return aop;
    }*/

    /**
     * mybatis持久层逻辑实现<br/>
     * <功能详细描述>
     *
     * @author Administrator
     * @version [版本号, 2019年5月2日]
     * @see [相关类/方法]
     * @since [产品/模块版本]
     */
    @Configuration
    public static class MybatisAuthContextPersisterConfiguration
            implements InitializingBean {

        /** 扫描业务日志的路径 */
        private String basePackages;

        /** 权限容器属性 */
        private ServiceLoggerContextProperties properties;

        /** <默认构造函数> */
        public MybatisAuthContextPersisterConfiguration(
                ServiceLoggerContextProperties properties) {
            this.properties = properties;
        }

        /**
         * @throws Exception
         */
        @Override
        public void afterPropertiesSet() throws Exception {
            this.basePackages = StringUtils
                    .isEmpty(properties.getBasePackages()) ? "com.tx"
                    : properties.getBasePackages();
        }

        /**
         * 业务日志句柄注册器
         * @return
         */
        @Bean
        public ServiceLoggerRegistry serviceLoggerRegistry(){
            ServiceLoggerRegistry registry = new ServiceLoggerRegistry(this.basePackages);
            return registry;
        }
    }
}
